package com.xoa.controller.party.work;

import com.xoa.dao.sms.SmsBodyMapper;
import com.xoa.dao.sms.SmsMapper;
import com.xoa.model.enclosure.Attachment;
import com.xoa.model.flowRunFeedback.FlowRunFeedback;
import com.xoa.model.sms.SmsBody;
import com.xoa.model.users.Users;
import com.xoa.model.workflow.FlowFast;
import com.xoa.model.workflow.FlowRun;
import com.xoa.model.workflow.FlowRunPrcs;
import com.xoa.service.ThreadSerivice.ThreadService;
import com.xoa.service.party.StreetFlowRunPrcsService;
import com.xoa.service.party.StreetWorkService;
import com.xoa.service.sms.SmsService;
import com.xoa.service.syspara.SysParaService;
import com.xoa.service.workflow.flowtype.FlowRunService;
import com.xoa.util.AjaxJson;
import com.xoa.util.CookiesUtil;
import com.xoa.util.DateFormat;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 创建作者:   张龙飞
 * 创建日期:   2017年5月22日 上午11:43:13
 * 类介绍  :    新建工作
 * 构造参数:
 */
@Controller
@RequestMapping("/street/workflow/work")
@SuppressWarnings("all")
public class StreetWorkController {

    @Resource
    private StreetFlowRunPrcsService flowRunPrcsService;

    @Resource
    private StreetWorkService workService;

    @Resource
    private SmsService smsService;

    @Resource
    private SysParaService sysParaService;

    @Autowired
    private ThreadService threadService;

    @Autowired
    private FlowRunService flowRunService;
    @Resource
    private SmsBodyMapper smsBodyMapper;

    private SmsMapper smsMapper;

    @RequestMapping("addwork")
    public String work(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/workflow/work/add_work";
    }
    @RequestMapping("workformh5")
    public String workformh5(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/party/workformh5";
    }
    @RequestMapping("workformh5PreView")
    public String workformh5PreView(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/party/workformh5PreView";
    }


    @RequestMapping("workformviewH5")
    public String workformviewH5() {
        return "app/workflow/work/workformviewH5";
    }






    @RequestMapping("turnh5")
    public String turnh5(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/party/turnh5";
    }    @RequestMapping("feedback")
    public String feedback(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/workflow/work/feedback";
    }
    @RequestMapping("newflowguider")
    public String addflowGuider(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/workflow/work/newFlowGuider";
    }
    @RequestMapping("workList")
    public String workList(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/workflow/work/workList";
    }

    @RequestMapping("workform")
    public String workform(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/party/workform";
    }

    @RequestMapping("workform1")
    public String workform1(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/workflow/work/workform1";
    }
    @RequestMapping("workformPreView")
    public String workformPreView(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/workflow/work/workformPreView";
    }

    @RequestMapping("notifyWork")
    public String notifyWork(HttpServletRequest request) {
        return "app/workflow/work/notifyWork";
    }

    @RequestMapping("workDelegate")
    public String workDelegate(HttpServletRequest request) {
        return "app/workflow/work/workDelegate";
    }

    //骆鹏添加2017/7/12
    @RequestMapping("/automaticNumbering")
    public String automaticNumbering() {
        return "app/workflow/work/automaticNumbering";
    }
    @RequestMapping("/automaticNumberingOne")
    public String automaticNumberingOne() {
        return "app/workflow/work/automaticNumberingOne";
    }
    @RequestMapping("/numberingAdminister")
    public String numberingAdminister() {
        return "app/workflow/work/numberingAdminister";
    }




    @RequestMapping("/businessApplications")
    public String businessApplications(HttpServletRequest request) {
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        if (!sysParaService.checkIsHaveSecure(user,5)){
            return "app/common/development";
        }
        return "app/workflow/work/businessApplications";
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月7日 上午10:31:07
     * 方法介绍:   快速新建
     * 参数说明:   @param request 请求
     * 参数说明:   @param flowId  流程id
     * 参数说明:   @param prcsId(flowStep)  步骤id对应flow_run_prcs的prcsId
     * 参数说明:   @param flowPrcs(prcsId)  流程实例步骤id对应flow_run_prcs的flowPrcs以及flow_procsee的prcsId
     * 参数说明:   @return
     * @return     ToJson<FlowFast>
     */
    @RequestMapping("workfastAdd")
    @ResponseBody
    public ToJson<FlowFast> fastAdd(HttpServletRequest request,
                                    Integer flowId,
                                    @RequestParam(value="flowStep",required = false) Integer prcsId,
                                    @RequestParam(value="prcsId",required = false) String flowProcs,
                                    @RequestParam(value="runId",required = false) String id,
                                    @RequestParam(value="runName",required = false) String runName
    ) {
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        String sqlType = "xoa" + (String) request.getSession().getAttribute(
                "loginDateSouse");
        String tableName=request.getParameter("tableName");
        String tabId=request.getParameter("tabId");
        if (!StringUtils.checkNull(flowProcs)){
            threadService.addNewworkFastAdd(user,flowId,prcsId,flowProcs,id,tableName,tabId,sqlType);
        }

        return workService.workFastAdd(user, flowId, prcsId, flowProcs, id,request,sqlType, runName);
    }

    @RequestMapping("createGuide")
    @ResponseBody
    public AjaxJson createGuide(String flowId, HttpServletRequest request){
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        return workService.createGuide(flowId, user,request);
    }



    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年5月27日 上午9:54:09
     * 方法介绍:   转交保存表单数据
     * 参数说明:   @param flowId 流程id
     * 参数说明:   @param prcsId 流程实例步骤id
     * 参数说明:   @param flowPrcs 步骤id
     * 参数说明:   @param formdata 表单json串
     * 参数说明:   @param runId  flowRun的流程实例Id
     * 参数说明:   @param runName flowRun的流程实例名称
     * 参数说明:   @param beginTime flowRun流程实例创建时间
     * 参数说明:   @param beginUser  flowRun流程发起人Id
     * 参数说明:   @return
     * @return     ToJson<FlowFast>
     */
    @RequestMapping("nextwork")
    @ResponseBody
    public ToJson<FlowFast> nextwork(HttpServletRequest request,
                                     @RequestParam(value="flowId",required = false) String flowId,
                                     @RequestParam(value="formdata",required = false) String formdata,
                                     @RequestParam(value="modifydata",required = false) String modifydata,
                                     @RequestParam(value="formLength",required = false) String formlength,
                                     @RequestParam(value="runId",required = false) int runId,
                                     @RequestParam(value="runName",required = false) String runName,
                                     @RequestParam(value="beginTime",required =false) String beginTime,
                                     @RequestParam(value="beginUser",required =false) String beginUser,
                                     @RequestParam(value="prcsId",required =false) String prcsId,
                                     @RequestParam(value="fromDataReject",required =false) String fromDateReject,
                                     @RequestParam(value="tableName",required =false) String tableName,
                                     @RequestParam(value="tabId",required =false) String tabId,
                                     @RequestParam(value="flowPrcs",required =false) String flowPrcs

    )  {
        String sqlType="xoa" + (String) request.getSession().getAttribute(
                "loginDateSouse");
        return workService.nextwork(flowId, formdata, modifydata ,formlength ,runId ,runName, beginTime, beginUser, sqlType, prcsId,fromDateReject,tableName,tabId,flowPrcs,request);
    }


    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月7日 上午10:32:03
     * 方法介绍:   转交后保存
     * 参数说明:   @param request 请求
     * 参数说明:   @param runId  流程实例Id
     * 参数说明:   @param runName 流程实例名称
     * 参数说明:   @param flowId  流程id
     * 参数说明:   @param prcsId  流程实例步骤id
     * 参数说明:   @param prcsFlag  步骤状态
     * 参数说明:   @param flowPrcs  步骤id
     * 参数说明:   @param beginTime  流程实力创建时间
     * 参数说明:   @param beginUser 流程发起人id
     * 参数说明:   @param jingbanUser  经办人
     * 参数说明:   @return
     * @return     ToJson<FlowRunPrcs>
     */
    @RequestMapping("saveWork")
    @ResponseBody
    public ToJson<FlowRunPrcs> savework(HttpServletRequest request,
                                        @RequestParam(value="runId",required = false) String runId,
                                        @RequestParam(value="runName",required = false) String runName,
                                        @RequestParam(value="flowId",required = false) String flowId,
                                        @RequestParam(value="prcsId",required = false) String prcsId,
                                        @RequestParam(value="prcsflag",required = false) String prcsFlag,
                                        @RequestParam(value="flowPrcs",required = false) String flowPrcs,
                                        @RequestParam(value="beginTime",required =false) String beginTime,
                                        @RequestParam(value="beginUser",required =false) String beginUser,
                                        @RequestParam(value="jingbanUser",required =false) String jingbanUser,
                                        @RequestParam(value="orgAdd",required =false) String orgadd,
                                        @RequestParam(value="viewUser",required =false) String viewUser,
                                        @RequestParam(value="smsContent",required =false) String smsContent,
                                        @RequestParam(value="smsType",required =false) String smsType,
                                        @RequestParam(value="tabId",required =false) String tabId

    ) {
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());

        int prceid=Integer.parseInt(prcsId);
        int prceidt=Integer.parseInt(prcsId);
        String smsUrl= "/street/workflow/work/workform?opflag=1&flowId="  + Integer.valueOf(flowId) + "&prcsId="+ flowPrcs+"&flowStep="+ ++prceid +"&runId=" + runId + "&tabId="+tabId+"&tableName=grid_event&isNomalType=true&hidden=true";
       FlowRun flowRun= flowRunService.find(Integer.parseInt(runId));
         smsContent="流水号："+runId+"   "+flowRun.getRunName();
        if (orgadd!="") {
           SmsBody smsBody = new SmsBody(user.getUserId(), "7", DateFormat.getTime(DateFormat.getStrDate(new Date())), smsUrl, smsContent);
            Map<String,Object> map=new HashMap<>();
            map.put("smsType","7");
            map.put("remindUrl",smsUrl);
            SmsBody smsBody1=smsBodyMapper.querySmsBodyCon(map);
            if(smsBody1==null){
                ///ToJson<SmsBody> toJson = smsService.saveSms(smsBody, jingbanUser);
           }

        }

        //主办人提交消除事物提醒（结束流程时没有主办人）
        if("0".equals(flowPrcs) && "3".equals(prcsId)){
            smsUrl="/street/workflow/work/workform?opflag=1&flowId="  + Integer.valueOf(flowId) + "&prcsId="+ 5+"&flowStep="+ prcsId +"&runId=" + runId + "&tabId="+tabId+"&tableName=grid_event&isNomalType=true&hidden=true";
        }else{
            smsUrl="/street/workflow/work/workform?opflag=1&flowId="  + Integer.valueOf(flowId) + "&prcsId="+ prcsId+"&flowStep="+ prcsId +"&runId=" + runId + "&tabId="+tabId+"&tableName=grid_event&isNomalType=true&hidden=true";
        }

        smsService.updatequerySmsByType("7", user.getUserId(), smsUrl.trim());

        return workService.savework(runId, runName, flowId, prcsId, prcsFlag, flowPrcs, beginTime, beginUser, jingbanUser, viewUser, user);
    }
    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月3日 上午9:54:09
     * 方法介绍:   查询表单数据
     * 参数说明:   @param request 请求
     * 参数说明:   @param flowId 流程id
     * 参数说明:   @param runId  flowRun的流程实例Id
     * 参数说明:   @return
     * @return     Map<String,Object>
     */
    @RequestMapping("selectFlowData")
    @ResponseBody
    public Map<String,Object> fastAdd(HttpServletRequest request,
                                      @RequestParam(value="runId",required = false) String runId,
                                      @RequestParam(value="flowId",required = false) String flowId
    ){
        return workService.fastAdd(runId, flowId);
    }
    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月26日 上午9:54:09
     * 方法介绍:   公共附件上传
     * 参数说明:   @param files 上传的文件
     * 参数说明:   @param fmodule 模块名
     * 参数说明:   @param request  请求
     * 参数说明:   @return
     * @return     ToJson<Attachment>
     */
    @RequestMapping(value = "workUpload", produces = {"application/json;charset=UTF-8"},method = RequestMethod.POST)
    @ResponseBody
    public ToJson<Attachment> workUpload(@RequestParam(value = "file", required = false) MultipartFile[] files , String module, String runId,
                                         HttpServletRequest request){
        String company="xoa"+(String) request.getSession().getAttribute(
                "loginDateSouse");
        return workService.workUpload(files, company, module ,runId );
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月28日 上午9:54:09
     * 方法介绍:   查找公共附件
     * 参数说明:   @param runId 流程实例Id
     * 参数说明:   @return
     * @return     ToJson<Attachment>
     */
    @RequestMapping(value = "findworkUpload", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    @ResponseBody
    public ToJson<Attachment> findworkUpload(HttpServletRequest request, String runId){
        String company="xoa"+(String) request.getSession().getAttribute(
                "loginDateSouse");
        if (StringUtils.checkNull(company)){
            company="xoa1001";
        }
        String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
        return workService.findworkUpload(runId, company);
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月27日 上午10:32:03
     * 方法介绍:   保存会签意见
     * 参数说明:   @param runId  流程实例Id
     * 参数说明:   @param content 会签内容
     * 参数说明:   @param prcsId  流程实例步骤id
     * 参数说明:   @param flowPrcs  步骤id
     * 参数说明:   @param file  附件
     * 参数说明:   @return
     * @return     ToJson<FlowRunFeedback>
     */
    @RequestMapping(value = "workfeedback", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    @ResponseBody
    public ToJson<FlowRunFeedback> workfeedback(String content, String runId, String prcsId, String flowPrcs,
                                                HttpServletRequest request){
        String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
        return workService.workfeedback(content, runId, prcsId, flowPrcs, userId);
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月27日 上午10:32:03
     * 方法介绍:   查询会签意见
     * 参数说明:   @param runId  流程实例Id
     * 参数说明:   @param prcsId  流程实例步骤id
     * 参数说明:   @param flowPrcs  步骤id
     * 参数说明:   @return
     * @return     ToJson<FlowRunPrcs>
     */
    @RequestMapping(value = "findworkfeedback", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson findworkfeedback(HttpServletRequest request, String runId, String prcsId, String flowPrcs, String signlock){
        String company="xoa"+(String) request.getSession().getAttribute(
                "loginDateSouse");
        String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
        return workService.findworkfeedback(runId, prcsId, flowPrcs, userId, company, signlock);
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月27日 上午10:32:03
     * 方法介绍:   查询分支
     * 参数说明:   @param runId  流程实例Id
     * 参数说明:   @param flowId  流程实例步骤id
     * 参数说明:   @param flowPrcs  步骤id
     * 参数说明:   @return
     * @return     ToJson<FlowFast>
     */
    @RequestMapping(value = "findbranch", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    @ResponseBody
    public ToJson<FlowFast> findBranch(HttpServletRequest request, String flowId, String runId, String flowPrcs){
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        return workService.findBranch(flowId, runId, flowPrcs, user);
    }
    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年4月30日 上午9:52:22
     * 方法介绍:   删除工作流附件
     * 参数说明    @param runid 流程实例id
     * 参数说明:   @param aid 附件主键
     * 参数说明:   @param module 模块
     * 参数说明:   @param ym 年月
     * 参数说明:   @param attachmentId 附件id
     * 参数说明:   @param attachmenrName 附件名字
     * 参数说明:   @param company 公司
     * 参数说明:   @param response 响应
     * 参数说明:   @param request 请求
     * 参数说明:   @return
     */
    @RequestMapping(value = "deletework", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    @ResponseBody
    public ToJson delete(String runId,
                         @RequestParam("AID") String aid,
                         @RequestParam("MODULE") String module,
                         @RequestParam("YM") String ym,
                         @RequestParam("ATTACHMENT_ID") String attachmentId,
                         @RequestParam("ATTACHMENT_NAME") String attachmentName,
                         @RequestParam("COMPANY") String company,
                         HttpServletResponse response,
                         HttpServletRequest request){
        return workService.delete(runId, aid, module, ym, attachmentId, attachmentName, company, response, request);
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月27日 上午10:32:03
     * 方法介绍:   查询回退之前步骤
     * 参数说明:   @param runId  流程实例Id
     * 参数说明:   @param allowBack  回退状态
     * 参数说明:   @param prcsId  步骤id
     * 参数说明:   @return
     * @return     ToJson<FlowFast>
     */
    @RequestMapping(value = "getflowprcsdata", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    @ResponseBody
    public ToJson<FlowRunPrcs> getflowprcsdata(String allowBack, String runId, String prcsId){
        return workService.getflowprcsdata(allowBack, runId, prcsId);
    }

    /**
     * 创建作者:   张龙飞
     * 创建日期:   2017年6月27日 上午10:32:03
     * 方法介绍:   回退步骤插入
     * 参数说明:   @param runId  流程实例Id
     * 参数说明:   @param flowPrcs 当前流程实例步骤id
     * 参数说明:   @param prcsId  回退流程步骤id
     * 参数说明:   @param flowStep  当前流程步骤id
     * 参数说明:   @return
     * @return
     */
    @RequestMapping(value = "insertprcsdata", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson insertprcsdata(String runId, String flowStep, String prcsId, String flowPrcs, String feedback, HttpServletRequest request){
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        return workService.insertprcsdata(runId, flowStep, prcsId, flowPrcs, user, feedback);
    }


    /**
     * 创建作者:   张勇
     * 创建日期:   2017/5/24 20:29
     * 方法介绍:   查询待办工作
     * 参数说明:
     * @return
     */
    @RequestMapping(value = "selectWork", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    public @ResponseBody
    ToJson<FlowRunPrcs> selectObject(FlowRunPrcs flowRunPrcs, HttpServletRequest request,
                                     @RequestParam(value = "page", required = false) Integer page,
                                     @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                     @RequestParam(value = "useFlag", required = false) boolean useFlag

    ) {
        Map<String, Object> maps = new HashMap<String, Object>();
        if (StringUtils.checkNull(flowRunPrcs.getUserId())) {
            String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
            maps.put("userId", userId);
        } else {
            maps.put("userId", flowRunPrcs.getUserId());
        }
        if(!StringUtils.checkNull(flowRunPrcs.getMyworkconditions())){
            maps.put("myworkconditions",flowRunPrcs.getMyworkconditions());
        }
        return flowRunPrcsService.selectObject(maps, page, pageSize, useFlag);
    }

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/5/24 20:29
     * 方法介绍:   查询办结工作
     * 参数说明:
     *
     * @return
     */
    @RequestMapping(value = "selectEndWord", produces = {"application/json;charset=UTF-8"})
    public @ResponseBody
    ToJson<FlowRunPrcs> selectEnd(FlowRunPrcs flowRunPrcs, HttpServletRequest request,
                                  @RequestParam(value = "page", required = false) Integer page,
                                  @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                  @RequestParam(value = "useFlag", required = false) boolean useFlag
    ) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        Map<String, Object> maps = new HashMap<String, Object>();
        if (StringUtils.checkNull(flowRunPrcs.getUserId())) {
            String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
            maps.put("userId", userId);
        } else {
            maps.put("userId", flowRunPrcs.getUserId());
        }
        if(!StringUtils.checkNull(flowRunPrcs.getMyworkconditions())){
            maps.put("myworkconditions",flowRunPrcs.getMyworkconditions());
        }
        return flowRunPrcsService.selectEnd(maps, page, pageSize, useFlag);
    }

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/5/24 20:29
     * 方法介绍:   查询挂起工作
     * 参数说明:
     *
     * @return
     */
    @RequestMapping(value = "selectHang", produces = {"application/json;charset=UTF-8"})
    public @ResponseBody
    ToJson<FlowRunPrcs> selectEndHang(FlowRunPrcs flowRunPrcs, HttpServletRequest request,
                                      @RequestParam(value = "page", required = false) Integer page,
                                      @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                      @RequestParam(value = "useFlag", required = false) boolean useFlag) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        Map<String, Object> maps = new HashMap<String, Object>();
        if (StringUtils.checkNull(flowRunPrcs.getUserId())) {
            String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
            maps.put("userId", userId);
        } else {
            maps.put("userId", flowRunPrcs.getUserId());
        }
        if(!StringUtils.checkNull(flowRunPrcs.getMyworkconditions())){
            maps.put("myworkconditions",flowRunPrcs.getMyworkconditions());
        }
        return flowRunPrcsService.selectHang(maps, page, pageSize, useFlag);
    }


    /**
     * 创建作者:   张勇
     * 创建日期:   2017/5/24 20:29
     * 方法介绍:   查询所有工作
     * 参数说明:
     *
     * @return
     */
    @RequestMapping(value = "selectAll", produces = {"application/json;charset=UTF-8"})
    public @ResponseBody
    ToJson<FlowRunPrcs> selectAll(FlowRunPrcs flowRunPrcs, HttpServletRequest request,
                                  @RequestParam(value = "page", required = false) Integer page,
                                  @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                  @RequestParam(value = "useFlag", required = false) boolean useFlag
    ) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        Map<String, Object> maps = new HashMap<String, Object>();
        if (StringUtils.checkNull(flowRunPrcs.getUserId())) {
            String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
            maps.put("userId", userId);
        } else {
            maps.put("userId", flowRunPrcs.getUserId());
        }
        if(!StringUtils.checkNull(flowRunPrcs.getMyworkconditions())){
            maps.put("myworkconditions",flowRunPrcs.getMyworkconditions());
        }
        return flowRunPrcsService.selectAll(maps, page, pageSize, useFlag);
    }

    /**
     * 创建作者:   张勇
     * 创建日期:   2017/6/20 13:59
     * 方法介绍:   删除流程根据ID
     * 参数说明:
     * @return
     */
    @RequestMapping(value = "deleteRunPrcs", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    public @ResponseBody
    ToJson<FlowRunPrcs> deleteRunPrcs(FlowRunPrcs flowRunPrcs, HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        if (StringUtils.checkNull(flowRunPrcs.getUserId())) {
            String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
            flowRunPrcs.setUserId(userId);
        }
        return flowRunPrcsService.deleteRunPrcs(flowRunPrcs);
    }




//    /**
//     * 创建作者:   张勇
//     * 创建日期:   2017/6/1 11:40
//     * 方法介绍:  根据runId查询关联办理人的步骤和所在部门
//     * 参数说明:
//     * @return
//     */
//    @RequestMapping(value = "findAllNode", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
//    public @ResponseBody
//    ToJson<FlowRunPrcs> findAllNode(HttpServletRequest request,
//                                  @RequestParam(value = "runId", required = false) Integer runId) {
//        ContextHolder.setConsumerType("xoa" + (String) request.getSession().getAttribute(
//                "loginDateSouse"));
//        return flowRunPrcsService.findAllNode(runId);
//    }

    @RequestMapping("procseeDesign")
    public String procseeDesign(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/workflow/work/procseeDesign";
    }
    @RequestMapping("processSpeak")
    public String processSpeak(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/workflow/work/processSpeak";
    }


    @RequestMapping("exportFlowRun")
    @ResponseBody
    public ToJson<FlowFast> exportFlowRun(HttpServletRequest request,
                                          Integer flowId,
                                          @RequestParam(value="flowStep",required = false) Integer prcsId,
                                          @RequestParam(value="prcsId",required = false) String flowProcs,
                                          @RequestParam(value="runId",required = false) String id,
                                          @RequestParam(value="runName",required = false) String runName
    ) {
        Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        String sqlType = "xoa" + (String) request.getSession().getAttribute(
                "loginDateSouse");
        return workService.workFastAdd(user, flowId, prcsId, flowProcs, id,request,sqlType, runName);
    }


    @RequestMapping("/exportExcel")
    @ResponseBody
    public void exportExcel(HttpServletRequest request, HttpServletResponse response) {
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        //定义导出工作列表，1：待办，2：办结，3：全部
        String type = request.getParameter("type");
        workService.exportExcel(user, type, response);
    }

    /**
     * 创建作者:   季佳伟
     * 创建日期:   2017/8/23 16:50
     * 方法介绍:   根据前台传入的runId,prcsId,toId,flowPrcs,opFlag,从session中获取users
     * 参数说明:
     * @return
     */
    @RequestMapping("/entrust")
    @ResponseBody
    public ToJson<FlowRunPrcs> entrust(String runId, String prcsId, String toId,
                                       String flowPrcs, String opFlag, HttpServletRequest request){
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
        return workService.entrust(runId, prcsId, toId, flowPrcs,opFlag,user);
    }

    /**获取所有委托工作
     */
    @RequestMapping(value = "entrustWork", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    public @ResponseBody
    AjaxJson entrustWork(FlowRunPrcs flowRunPrcs, HttpServletRequest request,
                         @RequestParam(value = "page", required = false) Integer page,
                         @RequestParam(value = "pageSize", required = false) Integer pageSize,
                         @RequestParam(value = "useFlag", required = false) boolean useFlag

    ) {
        Map<String, Object> maps = new HashMap<String, Object>();
        if (StringUtils.checkNull(flowRunPrcs.getUserId())) {
            String userId = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users()).getUserId();
            maps.put("userId", userId);
        } else {
            maps.put("userId", flowRunPrcs.getUserId());
        }
        if(!StringUtils.checkNull(flowRunPrcs.getMyworkconditions())){
            maps.put("myworkconditions",flowRunPrcs.getMyworkconditions());
        }
        return flowRunPrcsService.entrustWork(maps, page, pageSize, useFlag);
    }

    /**根据强制合并查找该流程是否全部转交完毕
     * */
    @RequestMapping(value = "checkGatherNode", produces = {"application/json;charset=UTF-8"},method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson checkGatherNode(int runId, int prcsId, String userId, String flowPrcs ){
        AjaxJson ajaxJson = new AjaxJson();



        return ajaxJson;


    }


}
